/*******************************************************************************
 * Copyright (c) 2010 Marcelo Cataldo, Sangeeth Nambiar
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Activator.java
 * 
 * Implements the activator for the DInvinio plugin
 * 
 * Contributors:
 *    Marcelo Cataldo  - initial implementation 
 *    Sangeeth Nambiar - initial implementation
 *******************************************************************************/
package edu.cmu.isr.dinvenio;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

/**
 * The activator class controls the plug-in life cycle
 */
public class Activator extends AbstractUIPlugin {

	// The plug-in ID
	public static final String PLUGIN_ID = "edu.cmu.isr.dinvenio";
	
	// View IDs
	public static final String GRAPH_VIEW_ID     		= "edu.cmu.isr.dinvenio.ui.views.graphView";
	public static final String GRAPHCONTROLS_VIEW_ID 	= "edu.cmu.isr.dinvenio.ui.views.GraphControlsView";
	public static final String PROJECT_VIEW_ID 			= "edu.cmu.isr.dinvenio.ui.views.projectView";
	public static final String SETTINGS_VIEW_ID 		= "edu.cmu.isr.dinvenio.ui.views.settingsView";
	public static final String LAYERS_VIEW_ID 			= "edu.cmu.isr.dinvenio.ui.views.layers";
	public static final String PROPERTY_VIEW_ID 		= "edu.cmu.isr.dinvenio.ui.views.propertyViewer";
	public static final String LAYOUT_VIEW_ID 			= "edu.cmu.isr.dinvenio.ui.views.layout";
	
	// Perspective IDs
	public static final String DINVINIO_PERSPECTIVE_ID = "edu.cmu.isr.dinvenio.perspective";

	// The shared instance
	private static Activator plugin;

	// Public objects
	public static Controller myController;
	
	/**
	 * The constructor
	 */
	public Activator() {
		myController = new Controller();
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext context) throws Exception {
		super.start(context);
		plugin = this;
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext context) throws Exception {
		plugin = null;
		super.stop(context);
	}

	/**
	 * Returns the shared instance
	 *
	 * @return the shared instance
	 */
	public static Activator getDefault() {
		return plugin;
	}

	/**
	 * Returns an image descriptor for the image file at the given
	 * plug-in relative path
	 *
	 * @param path the path
	 * @return the image descriptor
	 */
	public static ImageDescriptor getImageDescriptor(String path) {
		return imageDescriptorFromPlugin(PLUGIN_ID, path);
	}
	
	public static IViewPart getGraphView() {
		return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(GRAPH_VIEW_ID);	
	}
	public static IViewPart getGraphControlsView() {
		return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(GRAPHCONTROLS_VIEW_ID);	
	}
	public static IViewPart getSettingsView() {
		return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(SETTINGS_VIEW_ID);	
	}
	public static IViewPart getLayersView() {
		return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(LAYERS_VIEW_ID);	
	}
	public static IViewPart getPropertyView() {
		return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(PROPERTY_VIEW_ID);	
	}
	public static IViewPart getProjectView() {
		return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(PROJECT_VIEW_ID);	
	}
	public static IViewPart getLayoutView() {
		return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(LAYOUT_VIEW_ID);	
	}
}
